package dryven.codegen.asm.typeinfo;


public class ArrayTypeInfo extends AbstractTypeInfo {

	private TypeInfo _arrayType;
	
	public ArrayTypeInfo(TypeInfo arrayType) {
		super();
		_arrayType = arrayType;
	}

	@Override
	public TypeInfo castPrimitiveUp(TypeInfo t) {
		return null;
	}

	@Override
	public int getPrimitiveCastScale() {
		return -1;
	}

	@Override
	public String getInternalClassName() {
		return getTypeDescriptor();
	}

	@Override
	public String getTypeDescriptor() {
		return "[L"+_arrayType.getInternalClassName()+";";
	}

	@Override
	public String getTypeName() {
		return "[L"+_arrayType.getTypeName()+";";
	}

	@Override
	public boolean isArray() {
		return true;
	}

	@Override
	public boolean isBoolean() {
		return false;
	}

	@Override
	public boolean isByte() {
		return false;
	}

	@Override
	public boolean isChar() {
		return false;
	}

	@Override
	public boolean isDouble() {
		return false;
	}

	@Override
	public boolean isFloat() {
		return false;
	}

	@Override
	public boolean isInt() {
		return false;
	}

	@Override
	public boolean isInterface() {
		return false;
	}

	@Override
	public boolean isLong() {
		return false;
	}

	@Override
	public boolean isReference() {
		return true;
	}

	@Override
	public boolean isRepresentedByInt() {
		return false;
	}

	@Override
	public boolean isShort() {
		return false;
	}

	@Override
	public boolean isVoid() {
		return false;
	}

	@Override
	public TypeInfo getSuperType() {
		return null;
	}

	@Override
	public boolean isAssignableTo(Class<?> clazz) {
		return clazz.equals(Object.class);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((_arrayType == null) ? 0 : _arrayType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ArrayTypeInfo other = (ArrayTypeInfo) obj;
		if (_arrayType == null) {
			if (other._arrayType != null)
				return false;
		} else if (!_arrayType.equals(other._arrayType))
			return false;
		return true;
	}
}
